package com.ruoyi.front;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.domain.SysAbout;
import com.ruoyi.system.domain.SysOssset;
import com.ruoyi.system.domain.SysSite;
import com.ruoyi.system.service.ISysAboutService;
import com.ruoyi.system.service.ISysOsssetService;
import com.ruoyi.system.service.ISysSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class footcontroller extends BaseController {
    @Autowired
    private ISysAboutService iSysAboutService;
    @Autowired
    ISysSiteService iSysSiteService;
    @Autowired
    private ISysOsssetService sysOsssetService;
    public void getabout(ModelMap modelMap) {

        HashMap<String, List<SysAbout>> abouthash = new HashMap<String,List<SysAbout>>();
        List<SysAbout> tem1 = new ArrayList<SysAbout>();
        SysAbout  sysAbout = new SysAbout();
        sysAbout.setState(1);
        List<SysAbout> sysAboutList = iSysAboutService.selectSysAboutList(sysAbout);
        for(int i=0;i<sysAboutList.size();i++)
        {
            if (abouthash.containsKey(sysAboutList.get(i).getGroupname())) {
                abouthash.get(sysAboutList.get(i).getGroupname()).add(sysAboutList.get(i));
            } else {
                tem1.clear();
                tem1.add(sysAboutList.get(i));
                List<SysAbout> list = new ArrayList<SysAbout>(tem1);
                abouthash.put(sysAboutList.get(i).getGroupname(), list);
            }
        }
        SysSite sysSite = iSysSiteService.selectSysSiteList(new SysSite()).get(0);
        modelMap.put("site",sysSite);
        modelMap.put("about",abouthash);

    }
    protected   Boolean ossFileExist(String strfile) {
        SysOssset sysOssset;
        sysOssset = sysOsssetService.selectSysOsssetList(new SysOssset()).get(0);
        OSS ossClient = new OSSClientBuilder().build(sysOssset.getEndpoint(), sysOssset.getKeyid(), sysOssset.getKeysecret());
        return  ossClient.doesObjectExist(sysOssset.getBucket(), strfile);
    }
}
